package com.lookpoint.util;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.po.LikeTable;
import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.baomidou.mybatisplus.generator.query.SQLQuery;

import java.util.Collections;

/**
 * @ClassName MybatisPlusGenerator
 * @Author luozongwei
 * @Date 2023/11/13 11:50
 * @Version 1.0
 * @Description
 */
public class MybatisPlusGenerator {
    public static void main(String[] args) {
        String url = "jdbc:mysql://localhost:3306/lookpoint?characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowMultiQueries=true";
        String username = "root";
        String password = "root";
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author("wheel") // 设置作者
                             .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("E:\\Code\\IdeaWorkSpace\\CMS\\src\\main\\java") // 指定输出目录
                            .commentDate("yyyy-MM-dd")
                            .disableOpenDir();
                })
                .dataSourceConfig(builder -> builder.databaseQueryClass(SQLQuery.class).typeConvert(new MySqlTypeConvert()).dbQuery(new MySqlQuery()))
                .packageConfig(builder -> {
                    builder.parent("com.lookpoint") // 设置父包名
                            // .moduleName("system") // 设置父包模块名
                            .entity("pojo")
                            .controller("controller")
                            .pathInfo(Collections.singletonMap(OutputFile.xml, "E:\\Code\\IdeaWorkSpace\\CMS\\src\\main\\resources\\mapper")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    // 设置entity类信息
                    builder.entityBuilder().enableFileOverride();
                    builder.mapperBuilder().enableFileOverride().enableBaseResultMap().enableBaseColumnList().build();
                    builder.likeTable(new LikeTable("cms_"))
                            .addTablePrefix("cms_"); // 设置过滤表前缀
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
